<template>
  <div id="app">
    <mt-header fixed title="传智播客.黑马程序员vue商城">
      <div v-if="isshow" slot="left" id="back">
        <a href="javascript:void(0)" @click="toback">返回</a>
      </div>
    </mt-header>

    <router-view/>
    
    <nav class="mui-bar mui-bar-tab">
			<router-link class="mui-tab-item" to="/home">
				<span class="mui-icon mui-icon-home"></span>
				<span class="mui-tab-label">首页</span>
			</router-link>
			<router-link class="mui-tab-item" to="/member">
				<span class="mui-icon mui-icon-contact"></span>
				<span class="mui-tab-label">会员</span>
			</router-link>
			<router-link class="mui-tab-item" to="/shopcar">
				<span class="mui-icon mui-icon-extra mui-icon-extra-cart">
          <span class="mui-badge" id="badge">0</span>
        </span>
				<span class="mui-tab-label">购物车</span>
			</router-link>
			<router-link class="mui-tab-item" to="/search">
				<span class="mui-icon mui-icon-search"></span>
				<span class="mui-tab-label">搜索</span>
			</router-link>
		</nav>
  </div>
</template>

<script>
import {vm,COUNTSTR} from './kits/vm.js'
vm.$on(COUNTSTR,function(count){
  var badgeobj = document.getElementById('badge');
  badgeobj.innerText = parseInt(badgeobj.innerText) + count;
});
export default {
  name: 'app',
  data(){
    return {
      isshow: false
    }
  },
  watch:{
			'$route':function(newroute,oldroute){
				if(newroute.path.toLowerCase() == '/home'){
					this.isshow = false;
				}else{
					this.isshow = true;
				}
			}
		},
  methods:{
    toback(){
      this.$router.go(-1);
    }
  }
}


</script>

<style>
body{
  background-color: #ffffff;
}
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  background-color: #fff;
}
.container{
  margin-top: 40px;
  margin-bottom: 50px;
}
#back a{
	color:white;
	font-size: 16px;
	font-weight: bold;
}
</style>
